<template>

  <div class="pb50">
    <el-form size="small" ref="form" :model="form" label-width="150px">
      <!--基础设置-->
      <BasicIndex :form="form"></BasicIndex>
      <!--活动时间-->
      <Datetime :form="form"></Datetime>
      <!--其它-->
      <Other :form="form"></Other>
    </el-form>

    <!--提交-->
    <div class="common-button-wrapper">
      <el-button size="small" @click="cancelFunc">取消</el-button>
      <el-button
        size="small"
        type="primary"
        @click="onSubmit"
        :loading="loading"
        >提交</el-button
      >
    </div>
  </div>
</template>
<script>
import { addActive } from "@/api/seckill.js";
import BasicIndex from "./part/Basic.vue";
import Datetime from "./part/Datetime.vue";
import Other from "./part/Other.vue";
export default {
  components: {
    /*基础设置*/
    BasicIndex,
    /*活动时间*/
    Datetime,
    /*其它*/
    Other,
  },
  data() {
    return {
      /*表单对象*/
      form: {
        image_id: 0,
        /*活动日期*/
        active_date: "",
        /*活动时间*/
        active_time: "",
        /*报名截止日期*/
        join_end_time: "",
        /*标题*/
        title: "",
        /*是否生效，默认1为生效，0为不生效*/
        status: 1,
        /*默认排序*/
        sort: 100,
        /*商品源数据*/
        tableData: [],
        /*商品列表*/
        product_list: [],
      },
      /*是否正在加载*/
      loading: false,
    };
  },
  created() {},
  methods: {
    /*提交表单*/
    onSubmit() {
      let self = this;
      self.$refs.form.validate((valid) => {
        if (valid) {
          let params = self.form;
          self.loading = true;
          addActive(params, true)
            .then((data) => {
              self.loading = false;
              ElMessage({
                message: "恭喜你，添加成功",
                type: "success",
              });
              self.cancelFunc();
            })
            .catch((error) => {
              self.loading = false;
            });
        }
      });
    },
    /*取消*/
    cancelFunc() {
      this.$router.back(-1);
    },
  },
};
</script>
